<template>
  <el-dialog title="歌单详情" :visible.sync="visiable" width="50%" :before-close="handleClose">
    <el-form ref="formData" :model="formData" label-width="100px"  >
      <el-form-item label="歌单名称:">
        <el-input v-model="formData.name" readonly></el-input>
      </el-form-item>
      <el-form-item label="封面图">
        <img :src="formData.img" style="width:178px; height:178px; display: block" />
      </el-form-item>
      <el-form-item label="歌单分类:">
        <el-input v-model="formData.categoryName" readonly></el-input>
      </el-form-item>
      <el-form-item label="创建时间:" prop="createTime">
        <el-date-picker
          value-format="yyyy-MM-dd HH:mm:ss"
          v-model="formData.createTime"
          type="datetime"
          placeholder="选择日期时间" readonly>
        </el-date-picker>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import musicApi from '@/api/music';
export default {
  props:{
    id: null,  // 歌单id
    visiable:{  // 弹出窗口
      type:Boolean,
      default:false
    },
    remoteClose: Function, //用于关闭窗口
  },

  watch: {
    // 监听visiable的变化 将改变之后的值传入
    visiable(val) {
      if(val) {
        this.fetchData();
      }
    },
  },

  data() {
      return {
        formData: {}, // 歌单详情
      }
  },

  methods: {
    // 查询歌单详情
    fetchData() {
        musicApi.getSongListById(this.id).then(response => {
            if (response.code === 200) {
                this.formData = response.data;
            }
        })
    },
    
    // 关闭窗口
    handleClose() {
      // 调用父组件的方法关闭窗口
      this.remoteClose();
    },
  }
}
</script>

<style scoped>

</style>
